<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Pptv
 *
 * @author dragon.hu add @2016.2.22
 */
require_once 'BaseChannel.php';

//PPTV
class Pptv implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="240369c3f03e540c4c284e2af1a77cc0"; //支付key
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("pptv", $_REQUEST);
		
		$sid = $_REQUEST['sid'];  //服务器标识，使用字母与数字的组合
		$roid = $_REQUEST['roid'];  //服务器角色id
		$username = $_REQUEST['username'];  //用户名
		$oid = $_REQUEST['oid'];  //订单号
		$amount = $_REQUEST['amount'];  //充值金额 元
		$extra = $_REQUEST['extra'];  //CP订单号
		$time = $_REQUEST['time'];  //时间戳
		$sign = $_REQUEST['sign'];  //签名
		
		$mysign = $sid.$username.$roid.$oid.$amount.$time.$paymentKey;
		
		$result = array();
		if($sign == md5($mysign)) 
		{ //验证通过进行发货
			if(false == $orderLog->recordOrder(STATUS_SUCCESS, $amount, $extra, "pptv", $platform,$oid))
			{
				$result['code'] = '2';
				$result['message'] = 'insert into db failed';
				$orderLog->log("pptv",array("order"=>$extra,"money"=>$amount,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$result['code'] = '1';
				$result['message'] = 'success';
				$orderLog->log("pptv",array("order"=>$extra,"money"=>$amount,"serverresult"=>"success"));
			}
			 
		} 
		else
		{
			$result['code'] = '4';
			$result['message'] = 'sign failed';
			$orderLog->log("pptv","order:$extra sign error sign:$sign mysign:$mysign");
		}
		$ret = json_encode($result);
		return $ret;
	}
	
}